<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layout 管理界面大布局示例 - Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 引入 layui.css -->
    <link href="//unpkg.com/layui@2.9.23/dist/css/layui.css" rel="stylesheet">
    <style>
        .manage {
            color: #357cb8;
        }
        
        .layui-elem-quote {
            border-left: none;
        }
        
        .add {
            display: flex;
            justify-content: flex-end;
        }
        
        .add button {
            width: 80px;
            height: 35px;
            background-color: #5cb85c;
            color: white;
            border-radius: 5px;
            border: none;
        }
        
        .layui-body {
            background-color: #edf0f2;
        }
        
        .layui-card-header button {
            width: 50px;
            height: 30px;
            background-color: #5cb85c;
            color: white;
            border-radius: 0px 3px 3px 0px;
            border: none;
            position: relative;
            top: 2px;
            right: 4px;
        }
        
        .layui-card-header input {
            height: 27px;
        }
    </style>
</head>

<body>
    <div class="layui-layout layui-layout-admin">
        <div class="layui-header">
            <div class="layui-logo layui-hide-xs layui-bg-black">头像框</div>
            <!-- 头部区域（可配合layui 已有的水平导航） -->
            <ul class="layui-nav layui-layout-left">
                <!-- 移动端显示 -->
                <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">
                    <i class="layui-icon layui-icon-spread-left"></i>
                </li>
            </ul>
            <ul class="layui-nav layui-layout-right">
                <li class="layui-nav-item layui-hide layui-show-sm-inline-block">
                    <a href="javascript:;">
                        <img src="//unpkg.com/outeres@0.0.10/img/layui/icon-v2.png" class="layui-nav-img"> 个人中心
                    </a>
                </li>
                <li class="layui-nav-item layui-hide layui-show-sm-inline-block">
                    <a href="javascript:;">
                        <img src="//unpkg.com/outeres@0.0.10/img/layui/icon-v2.png" class="layui-nav-img"> 退出
                    </a>
                </li>
            </ul>
        </div>
        <div class="layui-side layui-bg-black">
            <div class="layui-side-scroll">
                <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
                <ul class="layui-nav layui-nav-tree" lay-filter="test">
                    <li class="layui-nav-item"><a href="javascript:;">仪表盘</a></li>
                    <li class="layui-nav-item"><a href="javascript:;">讲师管理</a></li>
                </ul>
            </div>
        </div>
        <div class="layui-body">
            <!-- 内容主体区域 -->
            <div style="padding: 15px;">
                <blockquote class="layui-elem-quote layui-text">
                    <span class="manage">讲师管理</span>
                    <span>/</span>
                    <span>讲师列表</span>

                </blockquote>
                <blockquote class="layui-elem-quote layui-text add">
                    <button>添加讲师</button>
                </blockquote>
                <div class="layui-card layui-panel">
                    <div class="layui-card-header">
                        <div>
                            <input type="text">
                            <button>搜索</button>
                        </div>
                    </div>
                    <div class="layui-card-body">
                        <table border="1px">
                            <thead>
                                <tr>
                                    <th>编号</th>
                                    <th>姓名</th>
                                    <th>昵称</th>
                                    <th>出生日期</th>
                                    <th>性别</th>
                                    <th>手机号码</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td>1</td>
                                    <td>1</td>
                                    <td>1</td>
                                    <td>1</td>
                                    <td>1</td>
                                    <td>1</td>
                                    <td>
                                        <button>查看</button>
                                        <button>编辑</button>
                                        <button>注销</button>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
                <br><br>
            </div>
        </div>
        <div class="layui-footer">
            <!-- 底部固定区域 -->
            <div id="demo-laypage-normal-1"></div>
        </div>
    </div>

    <!-- 引入 layui.js -->
    <script src="../../../JQuery.js"></script>
    <script src="//unpkg.com/layui@2.9.23/dist/layui.js"></script>
    <script>
        //JS 
        layui.use(['element', 'layer', 'util'], function() {
            var element = layui.element;
            var layer = layui.layer;
            var util = layui.util;
            var $ = layui.$;

            //头部事件
            util.event('lay-header-event', {
                menuLeft: function(othis) { // 左侧菜单事件
                    layer.msg('展开左侧菜单的操作', {
                        icon: 0
                    });
                },
                menuRight: function() { // 右侧菜单事件
                    layer.open({
                        type: 1,
                        title: '更多',
                        content: '<div style="padding: 15px;">处理右侧面板的操作</div>',
                        area: ['260px', '100%'],
                        offset: 'rt', // 右上角
                        anim: 'slideLeft', // 从右侧抽屉滑出
                        shadeClose: true,
                        scrollbar: false
                    });
                }
            });


            let tbody = jQuery('tbody')

            //讲师列表数据渲染
            jQuery.ajax({
                type: 'get',
                url: 'http://47.94.4.201/index.php/index/teacher/teacherlist',
                dataType: 'json',
                success: s => {
                    //******************************分页******************************
                    var laypage = layui.laypage;
                    let x = s.data.data
                    console.log(s.data.data);
                    // 普通用法
                    laypage.render({
                        elem: 'demo-laypage-normal-1',
                        count: x.length, // 数据总数
                        limit: 5,
                        jump: function(obj) {
                            obj.curr
                            obj.limit
                            tbody.html('')
                            let page_turn_data = x.slice((obj.curr - 1) * obj.limit, obj.curr * obj.limit);
                            page_turn_data.forEach(item => {
                                tbody.append(
                                    `
                            <tr>
                                        <td>${item.id}</td>
                                        <td>${item.name}</td>
                                        <td>${item.nick}</td>
                                        <td>${item.birthdata}</td>
                                        <td>${item.sex}</td>
                                        <td>${item.iphone}</td>
                                        <td>
                                            <button onclicl=view()>查看</button>
                                            <button onclick=edit(${item.id},${item.name},${item.sex},${item.birthdata})>编辑</button>
                                            <button>注销</button>
                                            </td>
                                    </tr>
                                    `
                                )
                            })

                        }
                    });


                },
                error: e => {
                    console.log(e);
                }
            })
        });
    </script>
</body>

</html>